﻿window.onerror = function() {    return true;};

document.write("<link id=stylesheet href=/Skins/Red/Style.css type=text/css rel=stylesheet />");
//document.body.oncontextmenu = function() { return false; };
function putBillHead() {//输出单据头
    document.write("<table class=bill border=0 cellpadding=0 cellspacing=0>"
    + "<tr><td class=bill_topleft></td>"
    + "<td class=bill_top></td>"
    + "<td class=bill_topright></td></tr>"
    + "<tr><td class=bill_left></td><td class=bill_center>" );
}
function putBillFoot() {//输出单据脚边
    document.write("</td><td class=bill_right></td>"
    + "</tr><tr><td class=bill_bottomleft></td>"
    + "<td class=bill_bottom colspan=2></td></tr></table>");
}

function getObjectLeft(o) {//获得对象Left绝对位置

    var result = o.offsetLeft;
    while (o.offsetParent) {
        o = o.offsetParent;
        result += o.offsetLeft;
    }
    return result;
}

function getObjectTop(o) {//获得对象Top绝对位置
    var result = o.offsetTop;
    while (o.offsetParent) {
        o = o.offsetParent;
        result += o.offsetTop;
    }
    return result;
}


//日历脚本开始
function monthadd(m) {//日历换月
    cdate = new Date(cdate.getFullYear(), cdate.getMonth() + m, cdate.getDate());
    showcalendar();
}

function getweek(d) {//获得本月初周次
    var d0 = new Date(d.getFullYear(), 0, 1);
    var dn = Math.floor(d.getTime() / DMS) - Math.floor(d0.getTime() / DMS) + d0.getDay() + 1;
    return Math.floor((dn + 6) / 7);
}
function makedate(s) {//创建一个日期
    if (s.match(/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/g)
		|| s.match(/^[0-9]{4}年[0-9]{1,2}月[0-9]{1,2}日$/g)) {
        var t = s.replace("日", "");
        t = t.replace("年", "-");
        t = t.replace("月", "-");
        var ar = t.split("-");
        return (new Date(ar[0], ar[1] - 1, ar[2]));
    }
    else {
        var td = new Date();
        return (new Date(td.getFullYear(), td.getMonth(), td.getDate()));
    }
}
function makeweeks(d) {//创建周
    var ws = new Array(6);
    var w = getweek(d);
    for (var i = 0; i < 6; i++) {
        ws[i] = w;
        w++;
    }
    return (ws.join("<br>"));
}

function showcalendar() {
    var i, j;
    var dd;
    var d0 = new Date(cdate.getFullYear(), cdate.getMonth(), cdate.getDate() - cdate.getDay());
    var tmp = "<table border=0 cellspacing=1 cellpadding=0 style='border-collapse:separate;'>";
    var k = false;
    var cln;
    for (i = 0; i < 6; i++) {
        tmp += "<tr>";
        for (j = 0; j < 7; j++) {
            if (!k) {
                if (d0.getDate() == 1) k = true;
            }
            else {
                if (d0.getDate() == 1) k = false;
            }
            if (!k) {
                tmp += "<td class=de> </td>";
            }
            else {
                if (Math.floor(d0.getTime() / DMS) == Math.floor(idate.getTime() / DMS)) {
                    cln = "dc";
                }
                else if (Math.floor(d0.getTime() / DMS) == Math.floor(today.getTime() / DMS)) {
                    cln = "dh";
                }
                else {
                    cln = "dd";
                }
                dd = d0.getFullYear() + "年" + (d0.getMonth() + 1) + "月" + d0.getDate() + "日";
                tmp += "<td class=" + cln + " title='" + dd + "' onclick=pick(this);>" + d0.getDate() + "</td>";
            }
            d0 = new Date(d0.getFullYear(), d0.getMonth(), d0.getDate() + 1);
        }
        tmp += "</tr>";

    }
    tmp += "</table>";
    dmonth.innerHTML = cdate.getFullYear() + "年" + (cdate.getMonth() + 1) + "月";
    dweek.innerHTML = makeweeks(cdate);
    dcalendar.innerHTML = tmp;
}
function hidecalendar() {
    ds.style.display = 'none';
}
document.write("<div id=ds><table class=dt border=1 width=100% height=100% cellspacing=0 cellpadding=0 bordercolor=#ccddaa bgcolor=#FFFFFF>"
	+ "<tr><td class=dtop colspan=2 height=28 onselectstart=return(false);>"
	+ "<a class=bs title=上一年 onclick=monthadd(-12);>&lt;&lt;</a>"
	+ " <a class=bs title=上一月 onclick=monthadd(-1);>&lt;</a>"
	+ " <span id=dmonth title=选择月份>月日</span>"
	+ " <a class=bs title=下一月 onclick=monthadd(1);>></a>"
	+ " <a class=bs title=下一年 onclick=monthadd(12);>>></a>"
	+ " <a class=bs title=选取今天 onclick=picktoday()>◎</a>"
	+ " <a class=bs title=关闭日期选择器 onclick=hidecalendar()><b>×</b></a>"
	+ "</td></tr>"
	+ "<tr><td width=20 height=22 align=center>周</td>"
	+ "<td class=dday height=22>日 一 二 三 四 五 六</td>"
	+ "</td></tr>"
	+ "<tr><td id=dweek width=20></td>"
	+ "<td id=dcalendar align=center></td></tr></table></div>");

var DMS = 86400000;
var idate; //初始日期
var cdate; //当前日期
var obj; //目标对象
var today = makedate(""); //今天
var ds = document.getElementById("ds");
var dmonth = document.getElementById("dmonth");
var dweek = document.getElementById("dweek");
var dcalendar = document.getElementById("dcalendar");

//日历功能函数，以下3个函数需要根据不同情况自定义
function pick(o) {
    obj.value = o.title;
    hidecalendar();
    obj.fireEvent("onchange");
}
function picktoday() {
    obj.value = today.getFullYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日";
    hidecalendar();
    obj.fireEvent("onchange");
}
function makecalendar(d, o) {
    obj = o;
    idate = makedate(d);
    cdate = new Date(idate.getFullYear(), idate.getMonth(), 1);
    ds.style.left = getObjectLeft(o) + "px";
    ds.style.top = (getObjectTop(o) + 25) + "px";
    ds.style.display = 'block';
    showcalendar();
}


//日历脚本结束

//下拉选择脚本开始
document.write("<div id=dddiv style=position:absolute;left:0px;top:0px;display:none;></div>");
var dddiv = document.getElementById("dddiv");
var ddhot = null;
function ddshow(o, list, xx, xy) {
    ddhot = o;
    dddiv.style.left = (getObjectLeft(o) + xx) + "px";
    dddiv.style.top = (getObjectTop(o) + xy) + "px";
    dddiv.style.display = "block";
    var lista = list.split("||");
    var op ="";
    for (var i = 0; i < lista.length; i++) {
        if (lista[i] == o.value) {
            op += "<option selected>" + lista[i] + "</option>";
        }
        else {
            op += "<option>" + lista[i] + "</option>";
        }
    }

    //dddiv.innerHTML = "<select class=dd id=dropdown onblur=ddcomeback(); style=border:0px;width:" + (o.clientWidth + 2) + "px>" + op + "</select>";
    dddiv.innerHTML = "<select class=dd id=dropdown onblur=ddcomeback(); style=border:1px;>" + op + "</select>";
    var dropdown = document.getElementById("dropdown");
    dropdown.setActive();
    dropdown.focus();
}

function ddcomeback() {
    var dropdown = document.getElementById("dropdown");
    dddiv.style.display = "none";
    ddhot.value = dropdown.options[dropdown.selectedIndex].text;
}


//下拉选择脚本结束


//var settings = new Array();
//settings["供货单位"] = "供货单位1||供货单位2||供货单位3";
